home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 December / PCWorld_2004-12_cd.bin / software / temacd / tiny / tf6pro-6[1].0.140.exe / Tiny Firewall Pro 6.0.msi / simple.js < prev    next >
Encoding:
JavaScript  |  2004-07-20  |  5.1 KB  |  215 lines

  1. /*//////////////////////////////////////////////////////////////////////
  2. filename:         simple.js
  3. copyright(c):     2003 Tiny Software Inc (http://www.tinysoftware.com)
  4. author:         Martin Navratil
  5. product:         Tiny Personal Firewall 5.x
  6. description:     simple mode handlers and functions
  7. ///////////////////////////////////////////////////////////////////////*/
  8.  
  9. var    AR_PREVENT = 0,
  10.     AR_ALLOW = 1,
  11.     AR_ASKUSER = 2,
  12.     AL_IGNORE = 0,
  13.     AL_MONITOR = 1,
  14.     AL_ALERT = 2;
  15.  
  16.  
  17. var PROP_CLPORT_OPEN = 0,
  18.     PROP_CLPORT_CLOSE_NOICS = 1,
  19.     PROP_CLPORT_CLOSE_ICS = 2;
  20.     
  21. function valueOfRadio(r, n)
  22. {
  23.     for (i = 0; i < n; i++) if (r[i].checked==true) 
  24.         return parseInt(r[i].value);
  25.     return 0;
  26. }
  27.         
  28. function setRadio(value, r, n)
  29. {
  30.     for (i = 0; i < n; i++) 
  31.         r[i].checked = (i == value);
  32. }
  33.     
  34. function SetInitValues()
  35. {
  36.     var chkIcs = document.all['CHK_ICS'], chkClPort = document.all['CHK_CLPORT'], chkClpal = document.all['CHK_CLPORTAL'],
  37.         radNetbios = document.all['RAD_NETBIOS'], chkSpawn = document.all['CHK_SPAWN'], 
  38.         chkUnkAppStart = document.all['CHK_UNKAPPSTART'];
  39.  
  40.     var propClPort, propClPortAL, propUnkAppStart, fwRuleList, sbxRuleList;
  41.     try
  42.     {
  43.         propClPort = propListFW.Get("PreventClosedPortAccess");
  44.     }
  45.     catch (e)
  46.     {
  47.         alert("Could not get PreventClosedPortAccess option");
  48.         return TXT_ERROR;
  49.     }
  50.     try
  51.     {
  52.         propClPortAL = propListFW.Get("ClosedPortAccessAL");
  53.     }
  54.     catch (e)
  55.     {
  56.         alert("Could not get ClosedPortAccessAL option");
  57.         return TXT_ERROR;
  58.     }
  59.     try
  60.     {
  61.         propUnkAppStart = propListSBX.Get("UnkAppStartDlg");
  62.     }
  63.     catch (e)
  64.     {
  65.         alert("Could not get UnkAppStartDlg option");
  66.         return TXT_ERROR;
  67.     }
  68.     try
  69.     {
  70.         var fwParser = window.external.ServerParser(2)
  71.         fwRuleList = fwParser.RuleList;
  72.     }
  73.     catch (e)
  74.     {
  75.         alert("Could not get Firewall rule list");
  76.         return TXT_ERROR;
  77.     }
  78.     try
  79.     {
  80.         var sbxParser = window.external.ServerParser(1)
  81.         sbxRuleList = sbxParser.RuleList;
  82.     }
  83.     catch (e)
  84.     {
  85.         alert("Could not get Sandbox rule list");
  86.         return TXT_ERROR;
  87.     }
  88.  
  89.     chkClPort.checked = (propClPort.value != PROP_CLPORT_OPEN);
  90.     chkIcs.checked = (propClPort.value == PROP_CLPORT_CLOSE_ICS);
  91.     chkIcs.disabled = propClPort.value == PROP_CLPORT_OPEN;
  92.     chkClpal.checked =     propClPortAL.value;
  93.     chkUnkAppStart.checked = propUnkAppStart.value;
  94.     
  95.     var arNetbios = window.external.RuleAccess("netbios");
  96.     switch (arNetbios)
  97.     {
  98.     case AR_ALLOW:
  99.         setRadio(0, radNetbios, 2);
  100.         break;
  101.     case AR_PREVENT:
  102.         setRadio(1, radNetbios, 2);
  103.         break;
  104.     default:
  105.         alert("Unknown access result of Netbios");
  106.         break;        
  107.     }
  108.     document.all['CHK_RUNKEYS'].checked = (window.external.RuleAccess("runkeys") == AR_ASKUSER) ? 1 : 0;
  109.     document.all['CHK_IEKEYS'].checked = (window.external.RuleAccess("iekeys") == AR_ASKUSER) ? 1 : 0;
  110.     document.all['CHK_INSTALLSVC'].checked = (window.external.RuleAccess("installsvc") == AR_ASKUSER) ? 1 : 0;
  111.     document.all['CHK_SPAWN'].checked = (window.external.RuleAccess("spawn") == AR_ASKUSER) ? 1 : 0;
  112.     document.all['CHK_VBARUNINORIG'].checked = (window.external.RuleAccess("vba") == AR_PREVENT) ? 1 : 0;
  113.  
  114. }
  115.  
  116. function OnClosedPortChange()
  117. {
  118.     var propClPort;
  119.     try
  120.     {
  121.         propClPort = propListFW.Get("PreventClosedPortAccess");
  122.     }
  123.     catch (e)
  124.     {
  125.         alert("Could not get PreventClosedPortAccess option");
  126.         return TXT_ERROR;
  127.     }
  128.     var chkIcs = document.all['CHK_ICS'], chkClPort = document.all['CHK_CLPORT'];
  129.     var bNewVal = chkClPort.checked;
  130.     var bValIcs = chkIcs.checked;
  131.     if (bNewVal)
  132.     {
  133.         chkClPort.checked = true;
  134.         chkIcs.disabled = false;
  135.         window.external.RuleAccess("icmp") = AR_PREVENT;
  136.         if (bValIcs)
  137.         {
  138.             propClPort.value = PROP_CLPORT_CLOSE_ICS;
  139.             chkIcs.checked = true;
  140.         }
  141.         else
  142.         {
  143.             propClPort.value = PROP_CLPORT_CLOSE_NOICS;
  144.             chkIcs.checked = false;
  145.         }
  146.     }
  147.     else
  148.     {
  149.         chkClPort.checked = false;
  150.         propClPort.value = PROP_CLPORT_OPEN;
  151.         chkIcs.disabled = true;
  152.         chkIcs.checked = false;
  153.         window.external.RuleAccess("icmp") = AR_ALLOW;
  154.     }
  155. }
  156.  
  157. function OnClPortALChange()
  158. {
  159.     var propClPortAL;
  160.     try
  161.     {
  162.         propClPortAL = propListFW.Get("ClosedPortAccessAL");
  163.     }
  164.     catch (e)
  165.     {
  166.         alert("Could not get ClosedPortAccessAL option");
  167.         return TXT_ERROR;
  168.     }
  169.     var chkClpal = document.all['CHK_CLPORTAL'];
  170.     propClPortAL.value = chkClpal.checked;
  171. }
  172.  
  173. function OnNetbiosChange(i)
  174. {
  175.     setRadio(i, document.all['RAD_NETBIOS'], 2);
  176.     switch (i)
  177.     {
  178.     case 0:
  179.         window.external.SetRuleAccess("netbios", AR_ALLOW, AL_IGNORE);
  180.         break;
  181.     case 1:
  182.         window.external.RuleAccess("netbios", AR_PREVENT, AL_IGNORE);
  183.         break;
  184.     }
  185. }
  186.  
  187. function OnAccessResultChange(strRuleType, checkbox)
  188. {
  189.     var iNewAccess = checkbox.checked;
  190.     window.external.SetRuleAccess(strRuleType,
  191.         iNewAccess ? (strRuleType == "vba" ? AR_PREVENT : AR_ASKUSER) : AR_ALLOW,
  192.         iNewAccess ? AL_MONITOR : AL_IGNORE);
  193. }
  194.  
  195. function OnUnkAppStartChange()
  196. {
  197.     var propUnkAppStart = null;
  198.     try
  199.     {
  200.         propUnkAppStart = propListSBX.Get("UnkAppStartDlg");
  201.     }
  202.     catch (e)
  203.     {
  204.         alert("Could not get UnkAppStartDlg option");
  205.         return TXT_ERROR;
  206.     }
  207.     
  208.     var chkUnkAppStart = document.all['CHK_UNKAPPSTART'];
  209.     if (propUnkAppStart != null)
  210.     {
  211.         propUnkAppStart.value = chkUnkAppStart.checked ? 1 : 0;
  212.     }
  213. }
  214.  
  215.